<?php 
if(isset($_POST['SubmitImport']))
{
	if($_FILES['import']['name'])
	{
	$sourcename = "admin.xls";
	move_uploaded_file($_FILES['import']['tmp_name'], "uploads/excel/".$sourcename);
	}
	if($sourcename!="")
	{
		require_once 'excelRead/Excel/reader.php';
		$data = new Spreadsheet_Excel_Reader();
		
		$data->read('uploads/excel/admin.xls');
		
		error_reporting(E_ALL ^ E_NOTICE);
		$data->sheets[0]['numRows'];
		for ($j = 1; $j <= $data->sheets[0]['numRows']; $j++)
		{
			if($data->sheets[0]['cells'][$j+1][1]!="")
			{
				////// find exits or not 
				$check = mysql_num_rows(mysql_query("select * from tooltip where id='".$data->sheets[0]['cells'][$j+1][1]."'"));
				if($check>0)
				{
					$stru = "update tooltip set terms='".$data->sheets[0]['cells'][$j+1][2]."',definition='".$data->sheets[0]['cells'][$j+1][3]."',";
					$stru.="url='".$data->sheets[0]['cells'][$j+1][4]."' where id='".$data->sheets[0]['cells'][$j+1][1]."'";
					
					$exeu = mysql_query($stru);
				}
				else
				{
					$str = "insert into tooltip set terms='".$data->sheets[0]['cells'][$j+1][2]."',definition='".$data->sheets[0]['cells'][$j+1][3]."',";
					$str.="url='".$data->sheets[0]['cells'][$j+1][4]."'";
					//echo $str;
					$exe = mysql_query($str);
				} /// end of check if.
			}
		}	
		echo '<script>location.href="index.php?tc=tooltip";</script>';
	}
}
?>
<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Add Tooltip</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12" style="padding-right:45px;">
    <a href="index.php?tc=tooltip" class="font12">Manage Tooltip</a></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
<form action="" method="post" name="form1" enctype="multipart/form-data">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="8%" align="left" valign="middle">&nbsp;</td>
    <td width="4%" align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <div id="response" class="red" style="padding-left:100px;"></div>
    <div id="reports" class="red"></div></td>
  </tr>
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="middle" class="font12">Import</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td width="54%" align="left" valign="middle">
    <input type="file" id="import" name="import"/>
    </td>
    <td width="34%" align="left" valign="middle" class="font12">Export Product</td>
  </tr>
  <tr>
    <td align="left" valign="middle" class="font12">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td width="34%" align="left" valign="middle" class="font12"><a href="export.php" class="font12">Click here?</a></td>
    </tr>
  <tr>
    <td align="left" valign="middle" class="font12">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="middle" class="font12">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <input type="submit" name="SubmitImport" value="Submit" class="button_submit1" />
    </td>
  </tr>
  <tr>
    <td align="left" valign="middle" class="font12">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">&nbsp;</td>
  </tr>
  </table>
  </form>